/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */
package com.jjsj.web.api;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jjsj.common.core.domain.AjaxResult;
import com.jjsj.mall.entity.MallBanner;
import com.jjsj.mall.entity.MallNotice;
import com.jjsj.mall.entity.MallSetting;
import com.jjsj.mall.service.IMallBannerService;
import com.jjsj.mall.service.IMallSettingService;
import com.jjsj.mall.service.MallNoticeService;
import com.jjsj.mall.service.SwiftPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品api
 *
 * @author JJSJ
 * @date 2019-08-12 16:25:10
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/mall")
@Api(value = "mall", tags = "商城首页接口API")
public class MallHomeApi {

    private final MallNoticeService mallNoticeService;
    private final IMallBannerService mallBannerService;

    private final IMallSettingService mallSettingService;

    /**
     * 查询商城首页
     *
     * @param
     * @return R
     */
    @ApiOperation(value = "查询商城首页")
    @GetMapping("/index")
    public AjaxResult getIndex() {
        MallNotice mallNotice = new MallNotice();
        mallNotice.setStatus("0");

        Page page = new Page();
        List<OrderItem> orders = new ArrayList<>();
        OrderItem orderItem = new OrderItem();
        orderItem.setColumn("order_num");
        orderItem.setAsc(true);
        orders.add(orderItem);
        page.setOrders(orders);
        page.setCurrent(1);
        page.setSize(10);
        MallBanner mallBanner = new MallBanner();
        mallBanner.setBannerType("0");
        mallBanner.setBannerOn("0");
        mallBanner.setDelFlag("0");
        Map<String, Object> map = new HashMap<>();
        map.put("banner", mallBannerService.page1(page, mallBanner));

        Page page1 = new Page();
        List<OrderItem> orders1 = new ArrayList<>();
        OrderItem orderItem1 = new OrderItem();
        orderItem1.setColumn("update_time");
        orderItem1.setAsc(false);
        orders1.add(orderItem1);
        page1.setOrders(orders1);
        page1.setCurrent(1);
        page1.setSize(10);
        MallBanner mallBanner1 = new MallBanner();
        mallBanner1.setBannerOn("0");
        mallBanner1.setDelFlag("0");
        mallBanner1.setBannerType("1");
        map.put("ad", mallBannerService.page1(page1, mallBanner1));
        map.put("notice", mallNoticeService.selectNoticeList(mallNotice));
        return AjaxResult.success(map);
    }

    @ApiOperation(value = "查询商城设置")
    @GetMapping("/setting")
    public AjaxResult getMallSetting() {
        List<MallSetting> list = mallSettingService.selectMallSettingList(new MallSetting());
        if (list.size() > 0) {
            return AjaxResult.success(list.get(0));
        } else {
            return AjaxResult.success("");
        }
    }

    @ApiOperation(value = "查询商城设置")
    @GetMapping("/test")
    public AjaxResult test(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SwiftPayService gateWayService = new SwiftPayService();
        return AjaxResult.success();
    }

}
